window.ADF = window.ADF || {};
ADF.control = ADF.control || {};
ADF.domControl = ADF.domControl || {};
ADF.model = ADF.model || {};
ADF.policy = ADF.policy || {};
ADF.editpart = ADF.editpart || {};
ADF.figure = ADF.figure || {};
ADF.modalRenderer = ADF.modalRenderer || {};


ADF.tool = ADF.tool || {};
ADF.property = ADF.property || {};
ADF.propertyDescriptor = ADF.propertyDescriptor || {};
ADF._modalRendererMap = {};

ADF.util = ADF.util || {};

ADF.registerModalRenderer = function(id, instance){
    ADF._modalRendererMap[id] = instance;
}

ADF.getModalRenderer = function(id){
    return ADF._modalRendererMap[id];
}

/**
 * Created by zhengjiachao on 2017/4/16.
 */

ADF.propertyDescriptor.DefaultPropertyDescriptor = function(name, value, defaultValue, editable, title, hint){
    ADF.propertyDescriptor.DefaultPropertyDescriptor.superclass.constructor.call(this, name, value, defaultValue, editable);
    this.setTitle(title);
    this.setHint(hint || title);
    this.setEditorType("baseProperty.defaultTextEditor");
};

COM.util.defineClass(ADF.propertyDescriptor.DefaultPropertyDescriptor, AGEF.PropertyDescriptor,{

    
});ADF.propertyDescriptor.ColorPropertyDescriptor = function(name, value, defaultValue, editable, title, hint){
    ADF.propertyDescriptor.ColorPropertyDescriptor.superclass.constructor.call(this, name, value, defaultValue, editable);
    this.setTitle(title);
    this.setHint(hint || title);
    this.setEditorType("baseProperty.attrColorEditor");
};

COM.util.defineClass(ADF.propertyDescriptor.ColorPropertyDescriptor, AGEF.PropertyDescriptor,{

    
});/**
 * Created by zhengjiachao on 2017/4/16.
 */

ADF.model.BaseModel = function(){
    ADF.model.BaseModel.superclass.constructor.call(this);
    this.parent = null;
};

ADF.model.BaseModel.PROPERTY_ADFTAG = 'adftag';
ADF.model.BaseModel.PROPERTY_ADFINSTANCEID = 'ADFInstanceID';
ADF.model.BaseModel.PROPERTY_FONTSIZE = 'fontsize';
ADF.model.BaseModel.PROPERTY_COLOR = 'color';
ADF.model.BaseModel.PROPERTY_BORDER_TOP = 'border-top';
ADF.model.BaseModel.PROPERTY_BORDER_RIGHT = 'border-right';
ADF.model.BaseModel.PROPERTY_BORDER_BOTTOM = 'border-bottom';
ADF.model.BaseModel.PROPERTY_BORDER_LEFT = 'border-left';
ADF.model.BaseModel.PROPERTY_BACKGROUND = 'bg';
ADF.model.BaseModel.PROPERTY_TITLE = 'title';
ADF.model.BaseModel.PROPERTY_NAME = 'name';
ADF.model.BaseModel.PROPERTY_CONFIG = 'config';

COM.util.defineClass(ADF.model.BaseModel, AGEF.BaseModel,{

    initModel: function() {
        ADF.model.BaseModel.superclass.initModel.call(this);
        this.addPropertyDescriptor(new ADF.propertyDescriptor.DefaultPropertyDescriptor(ADF.model.BaseModel.PROPERTY_NAME, this._getName(), "", true, "名称"));
        this.addPropertyDescriptor(new ADF.propertyDescriptor.DefaultPropertyDescriptor(ADF.model.BaseModel.PROPERTY_ADFTAG, "", "", true, "ADFTag"));
        this.addPropertyDescriptor(new ADF.propertyDescriptor.DefaultPropertyDescriptor(ADF.model.BaseModel.PROPERTY_FONTSIZE, "", "", true, "字号"));
        this.addPropertyDescriptor(new ADF.propertyDescriptor.ColorPropertyDescriptor(ADF.model.BaseModel.PROPERTY_COLOR, "", "", true, "字体颜色"));
        this.addPropertyDescriptor(new ADF.propertyDescriptor.DefaultPropertyDescriptor(ADF.model.BaseModel.PROPERTY_BORDER_TOP, "1px solid #000", "", true, "上边框"));
        this.addPropertyDescriptor(new ADF.propertyDescriptor.DefaultPropertyDescriptor(ADF.model.BaseModel.PROPERTY_BORDER_RIGHT, "1px solid #000", "", true, "右边框"));
        this.addPropertyDescriptor(new ADF.propertyDescriptor.DefaultPropertyDescriptor(ADF.model.BaseModel.PROPERTY_BORDER_BOTTOM, "1px solid #000", "", true, "下边框"));
        this.addPropertyDescriptor(new ADF.propertyDescriptor.DefaultPropertyDescriptor(ADF.model.BaseModel.PROPERTY_BORDER_LEFT, "1px solid #000", "", true, "左边框"));
        this.addPropertyDescriptor(new ADF.propertyDescriptor.ColorPropertyDescriptor(ADF.model.BaseModel.PROPERTY_BACKGROUND, "", "", true, "背景颜色")); 
        this.addPropertyDescriptor(new ADF.propertyDescriptor.DefaultPropertyDescriptor(ADF.model.BaseModel.PROPERTY_TITLE, "", "", true, "提示信息"));
        this.addPropertyDescriptor(new ADF.propertyDescriptor.DefaultPropertyDescriptor(ADF.model.BaseModel.PROPERTY_CONFIG, "", "", false, "控件配置"));
    },

    _getName : function(){
        return 'base';  
    },

    serialize:function(){
        var jsonObject = JSON.parse(ADF.model.BaseModel.superclass.serialize.call(this));
        this._serializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_ADFTAG);
        this._serializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_COLOR);
        this._serializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_BORDER_TOP);
        this._serializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_BORDER_RIGHT);
        this._serializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_BORDER_BOTTOM);
        this._serializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_BORDER_LEFT);
        this._serializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_BACKGROUND);
        this._serializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_FONTSIZE);
        this._serializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_TITLE);
        this._serializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_NAME);
        this._serializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_CONFIG);
        this.fillSerializedJson(jsonObject);
        return COM.util.ObjUtil.stringify(jsonObject);
    },

    _serializeProp : function(jsonObject, key){
        if(this.getPropertyDescriptor(key)){
            jsonObject[key]=this.getPropertyDescriptor(key).serialize();
        }
    },

    setBorderTop: function(border) {
        this.setPropertyValue(ADF.model.BaseModel.PROPERTY_BORDER_TOP, border);
    },
    getBorderTop: function() {
        return this.getPropertyValue(ADF.model.BaseModel.PROPERTY_BORDER_TOP);
    },
    setBorderRight: function(border) {
        this.setPropertyValue(ADF.model.BaseModel.PROPERTY_BORDER_RIGHT, border);
    },
    getBorderRight: function() {
        return this.getPropertyValue(ADF.model.BaseModel.PROPERTY_BORDER_RIGHT);
    },
    setBorderBottom: function(border) {
        this.setPropertyValue(ADF.model.BaseModel.PROPERTY_BORDER_BOTTOM, border);
    },
    getBorderBottom: function() {
        return this.getPropertyValue(ADF.model.BaseModel.PROPERTY_BORDER_BOTTOM);
    },
    setBorderLeft: function(border) {
        this.setPropertyValue(ADF.model.BaseModel.PROPERTY_BORDER_LEFT, border);
    },
    getBorderLeft: function() {
        return this.getPropertyValue(ADF.model.BaseModel.PROPERTY_BORDER_LEFT);
    },
    setColor: function(color) {
        this.setPropertyValue(ADF.model.BaseModel.PROPERTY_COLOR, color);
    },
    getColor: function() {
        return this.getPropertyValue(ADF.model.BaseModel.PROPERTY_COLOR);
    },
    setBackground: function(bg) {
        this.setPropertyValue(ADF.model.BaseModel.PROPERTY_BACKGROUND, bg);
    },
    getBackground: function() {
        return this.getPropertyValue(ADF.model.BaseModel.PROPERTY_BACKGROUND);
    },
    setFontsize: function(fontsize) {
        this.setPropertyValue(ADF.model.BaseModel.PROPERTY_FONTSIZE, fontsize);
    },
    getFontsize: function() {
        return this.getPropertyValue(ADF.model.BaseModel.PROPERTY_FONTSIZE);
    },
    setTitle: function(title) {
        this.setPropertyValue(ADF.model.BaseModel.PROPERTY_TITLE, title);
    },
    getTitle: function() {
        return this.getPropertyValue(ADF.model.BaseModel.PROPERTY_TITLE);
    },
    setName: function(name) {
        this.setPropertyValue(ADF.model.BaseModel.PROPERTY_NAME, name);
    },
    getName: function() {
        return this.getPropertyValue(ADF.model.BaseModel.PROPERTY_NAME);
    },
    setConfig: function(config) {
        this.setPropertyValue(ADF.model.BaseModel.PROPERTY_CONFIG, config);
    },
    getConfig: function() {
        return this.getPropertyValue(ADF.model.BaseModel.PROPERTY_CONFIG);
    },


    setParent: function(parent){
        this.parent = parent;
    },

    removeParent: function(){
        this.parent = null;
    },

    getParent: function(){
        return this.parent;
    },

    getADFTag : function() {
        return this.getPropertyValue(ADF.model.BaseModel.PROPERTY_ADFTAG);
    },
    setADFTag: function(id) {
        this.setPropertyValue(ADF.model.BaseModel.PROPERTY_ADFTAG, id);
    },

    fillSerializedJson : function(jsonObject){

    },

    deserialize:function (jsonString) {
        var jsonObject = ADF.model.BaseModel.superclass.deserialize.call(this, jsonString);
        this._deserializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_ADFTAG);
        this._deserializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_BORDER_TOP);
        this._deserializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_BORDER_RIGHT);
        this._deserializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_BORDER_BOTTOM);
        this._deserializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_BORDER_LEFT);
        this._deserializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_COLOR);
        this._deserializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_BACKGROUND);
        this._deserializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_FONTSIZE);
        this._deserializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_TITLE);
        this._deserializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_NAME);
        this._deserializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_CONFIG);
        this._deserialize(jsonObject);
    },


    _deserialize:function(jsonObject){

    },

    
    clone: function() {
        var newModel = ADF.model.BaseModel.superclass.clone.call(this);
        newModel.id = undefined;
        return newModel;
    }
});/**
 * @author zhengjiachao
 * @since 2017-4-10
 */
ADF.model.CompoundModel = function(){
};

COM.util.defineClass(ADF.model.CompoundModel, Object ,{

    getModels : Function.needOverride,

    clone : Function.needOverride

});/**
 * Created by zhengjiachao on 2017/4/16.
 */

ADF.model.CompositeModel = function(){
    ADF.model.CompositeModel.superclass.constructor.call(this);
};
ADF.model.CompositeModel.PROPERTY_CHILDREN = "children";
COM.util.defineClass(ADF.model.CompositeModel, ADF.model.BaseModel,{

    initModel: function() {
        ADF.model.CompositeModel.superclass.initModel.call(this);
        var children = new AGEF.PropertyDescriptor(ADF.model.CompositeModel.PROPERTY_CHILDREN, []);
        var text = new AGEF.PropertyDescriptor("text", this._getShowText(), "", false);
        this.addPropertyDescriptor(children);
        this.addPropertyDescriptor(text);
    },


    addChild: function(child){
        var children = this.getPropertyValue(ADF.model.CompositeModel.PROPERTY_CHILDREN), newChildren = children.slice(0, children.length);
        newChildren.push(child);
        this._initChildLayoutData(child);
        this._initChildLayoutDataEditorType(child.getPropertyDescriptor(AGEF.BaseModel.PROPERTY_LAYOUTDATA));
        child.setParent(this);
        this.setPropertyValue(ADF.model.CompositeModel.PROPERTY_CHILDREN, newChildren);
    },

    //根据自己的规则，初始化子控件的布局数据
    _initChildLayoutData : function(child){
        var layoutdata=new COM.draw2d.Rectangle();
        COM.util.ObjUtil.copyProperty(layoutdata,child.getLayoutData());
        child.setLayoutData(layoutdata);
    },

    _initChildLayoutDataEditorType : function(descriptor){
        descriptor.setEditorType("baseProperty.XYLayoutDataEditor");
    },

    removeChild: function(child){
        var children = this.getPropertyValue(ADF.model.CompositeModel.PROPERTY_CHILDREN), newChildren = children.slice(0, children.length);
        child.removeParent();
        COM.util.Array.removeItem(newChildren, child);
        this.setPropertyValue(ADF.model.CompositeModel.PROPERTY_CHILDREN, newChildren);
    },
    getChildren: function(){
        return this.getPropertyValue(ADF.model.CompositeModel.PROPERTY_CHILDREN);
    },

    fillSerializedJson : function(jsonObject){
        ADF.model.CompositeModel.superclass.fillSerializedJson.call(this, jsonObject);
        var children = this.getChildren();
        jsonObject['children'] = [];
        for(var index in children) {
            jsonObject.children.push(children[index].serialize());
        }
        jsonObject["text"] = this.getPropertyDescriptor("text").serialize();
    },

    _deserialize: function(jsonObject){
        ADF.model.CompositeModel.superclass._deserialize.call(this, jsonObject);
        var children = jsonObject["children"];
        for(var index in children) {
            var childJsonObject = COM.util.ObjUtil.parseJSON(children[index]), modelType = childJsonObject["modelType"], modelConstructor = eval("("+modelType+")");
            var childModel = new modelConstructor();
            childModel.deserialize(children[index]);
            this.addChild(childModel);
        }
        var newProp = new AGEF.PropertyDescriptor();
        newProp.deserialize(jsonObject["text"]);
        this.propertyDescriptors.put(newProp.getName(), newProp);
    },

    
    _getShowText : function(){
        return "composite";
    }

});/**
 * @author zhengjiachao
 * @since 2017-4-16
 */
ADF.domControl.ControlMixin = {
    
    createDomElement: function(model) {
        this.domElement = this._getDomElement(model);
        this.setADFControlType();
        this.setADFTag(model.getADFTag());
        this.setADFID(model.getID());
        this.setBorderTop(model.getBorderTop());
        this.setBorderRight(model.getBorderRight());
        this.setBorderBottom(model.getBorderBottom());
        this.setBorderLeft(model.getBorderLeft());
        this.setColor(model.getColor());
        this.setBackground(model.getBackground());
        this.setFontsize(model.getFontsize());
        this.setTitle(model.getTitle());
        return this.domElement;
    },

    /* 布局結束后，复写此方法，做布局后的相应逻辑 */
    _afterLayout : function(){
    },

    setBorderTop:function (border) {
        this.domElement.style.borderTop = border;
    },

    setBorderRight:function (border) {
        this.domElement.style.borderRight = border;
    },

    setBorderBottom:function (border) {
        this.domElement.style.borderBottom = border;
    },

    setBorderLeft:function (border) {
        this.domElement.style.borderLeft = border;
    },

    setColor:function(color){
        this.domElement.style.color = color;
    },

    setBackground:function(bg){
        this.domElement.style.background = bg;
    },

    setFontsize:function(fontsize){
        this.domElement.style.fontSize = fontsize;
    },

    setTitle:function(title){
        this.domElement.title = title;
    },

    _getDomElement : Function.emptyFunction,

    setADFTag : function(tag){
        if(this.domElement){
            tag ? $(this.domElement).attr({'adftag' : tag}) : $(this.domElement).removeAttr('adftag');
        }
    },

    setADFID : function(id){
        if(this.domElement){
            id ? $(this.domElement).attr({'adfid' : id}) : $(this.domElement).removeAttr('adfid');
        }
    },

    setADFControlType : function(){
        var label = this.getLabel();
        if(this.domElement){
            $(this.domElement).attr({'ADF_Control_Type' : label});
        }
    }
};/**
 * @author zhengjiachao
 * @since 2017-4-16
 */
ADF.domControl.BaseControl = function(parent) {
    ADF.domControl.BaseControl.superclass.constructor.call(this, parent);
};

COM.util.defineClass(ADF.domControl.BaseControl, AGEF.Control, ADF.domControl.ControlMixin);

/**
 * Created by zhengjiahao on 2017/4/16.
 */

ADF.editpart.BaseEditpart = function () {
    ADF.editpart.BaseEditpart.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.editpart.BaseEditpart, AGEF.WidgetGraphicalEditPart, {

    propertyChange: function (evt) {
        ADF.editpart.BaseEditpart.superclass.propertyChange.call(this, evt);
        if (AGEF.PropertyChangeEvent.UPDATE_EVENT == evt.getType()) {
            if (ADF.model.BaseModel.PROPERTY_ADFTAG == evt.getPropertyName()) {
                this.getFigure().getWidget().setADFTag(evt.newValue);
            } else if (ADF.model.BaseModel.PROPERTY_BORDER_TOP == evt.getPropertyName()) {
                this.getFigure().getWidget().setBorderTop(evt.newValue);
            } else if (ADF.model.BaseModel.PROPERTY_BORDER_RIGHT == evt.getPropertyName()) {
                this.getFigure().getWidget().setBorderRight(evt.newValue);
            } else if (ADF.model.BaseModel.PROPERTY_BORDER_BOTTOM == evt.getPropertyName()) {
                this.getFigure().getWidget().setBorderBottom(evt.newValue);
            } else if (ADF.model.BaseModel.PROPERTY_BORDER_LEFT == evt.getPropertyName()) {
                this.getFigure().getWidget().setBorderLeft(evt.newValue);
            } else if (ADF.model.BaseModel.PROPERTY_COLOR == evt.getPropertyName()) {
                this.getFigure().getWidget().setColor(evt.newValue);
            } else if (ADF.model.BaseModel.PROPERTY_BACKGROUND == evt.getPropertyName()) {
                this.getFigure().getWidget().setBackground(evt.newValue);
            } else if (ADF.model.BaseModel.PROPERTY_FONTSIZE == evt.getPropertyName()){
                this.getFigure().getWidget().setFontsize(evt.newValue);
            } else if (ADF.model.BaseModel.PROPERTY_TITLE == evt.getPropertyName()){
                this.getFigure().getWidget().setTitle(evt.newValue);
            } else if (ADF.model.BaseModel.PROPERTY_CONFIG == evt.getPropertyName()){
                this.getFigure().getWidget().setConfig(evt.newValue);
            }
        }
    },

    createEditPolicies: function(){
        this.installEditPolicy(COM.gef.EditPolicy.COMPONENT_ROLE, new AGEF.ComponentEditPolicy());
    },
});/**
 * Created by zhengjiahao on 2017/4/16.
 */

ADF.editpart.CompositeEditpart = function () {
    ADF.editpart.CompositeEditpart.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.editpart.CompositeEditpart, ADF.editpart.BaseEditpart, {

    propertyChange: function (evt) {
        ADF.editpart.CompositeEditpart.superclass.propertyChange.call(this, evt);
        var prop = evt.getPropertyName();
        if("children" == prop) {
            this.refreshChildren();
        }
    }

});/**
 * @author zhengjiachao
 * @since 2017-3-27
 */
ADF.domControl.Composite = function Composite() {

    ADF.domControl.Composite.superclass.constructor.call(this);
}

COM.util.ObjUtil.defineClass(ADF.domControl.Composite, AGEF.Composite,[ADF.domControl.ControlMixin, {

    

}]);/**
 * @author zhengjiachao
 * @since 2017-3-27
 */
ADF.PropertyEditorControl = function PropertyEditorControl(propDescriptor) {

    ADF.PropertyEditorControl.superclass.constructor.call(this, propDescriptor);
}

COM.util.defineClass(ADF.PropertyEditorControl, AGEF.PropertyEditor,{

    getID : function(){
        return "emptyID";
    }

});/**
 * Created by zhengjiachao on 2017/5/15.
 */

ADF.modalRenderer.BaseModalRenderer = function(){
    ADF.modalRenderer.BaseModalRenderer.superclass.constructor.call(this);
};

ADF.modalRenderer.BaseModalRenderer.ID = "baseModalRenderer";

COM.util.defineClass(ADF.modalRenderer.BaseModalRenderer, Object,{

    init : function(container){
        this.container = container;
        this.$modalDom = $(this.getModelHTML());
        this.contentContainer = this.$modalDom.find('.modal-body')[0];
        this.$modalDom.find('.adf-ok').click(function(){
            if(this.closeCallback){
                var canClose = this.closeCallback(this._getContentData(this.contentContainer));
                // if(canClose === false){
                //     return;
                // }
            }
            this.$modalDom.modal('hide');
        }.bind(this));
        $(this.container).append(this.$modalDom);
    },

    getModelHTML : function(){
        var domStr = '\
            <div class="modal" tabindex="-1" role="dialog">\
                <div class="modal-dialog modal-lg" role="document">\
                    <div class="modal-content">\
                    <div class="modal-header">\
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>\
                        <h4 class="modal-title" id="gridSystemModalLabel">' + this._getTitle() + '</h4>\
                    </div>\
                    <div class="modal-body">\
                    </div>\
                    <div class="modal-footer">\
                        <button type="button" class="btn btn-default" data-dismiss="modal">' + this._getCancelButtonText() + '</button>\
                        <button type="button" class="btn btn-primary adf-ok">' + this._getOkButtonText() + '</button>\
                    </div>\
                    </div>\
                </div>\
            </div>\
        ';
        return domStr;
    },

    _getOkButtonText : function(){
        return '保存';
    },

    _getCancelButtonText : function(){
        return '取消';
    },
    
    _getTitle : function(){
        return '默认标题';
    },

    show : function(contentData, callback){
       this._renderBody(this.contentContainer, contentData);
       this.closeCallback = callback;
       this.$modalDom.modal('show');
    },

    _renderBody : function(parentDom, contentData){
    },

    _getContentData : function(parentDom){
        return "";
    },

    getID : function(){
        return ADF.modalRenderer.BaseModalRenderer.ID;
    }
    
});/**
 * @author 郑佳超
 * @since 2017-4-6
 */
ADF.PartFactory = function PartFactory(controlList) {
    this.controlList = controlList;
    ADF.PartFactory.superclass.constructor.call(this);
};
COM.util.defineClass(ADF.PartFactory, COM.gef.EditPartFactory,{
    createEditPart: function (context, model) {
        var part = null;
        for(var i = 0 ; i < this.controlList.length; i++){
            var control = this.controlList[i];
            var m = control.getModel();
            var ep = control.getEditpart();
            if(model.constructor === m){
                part = new ep();
                break;
            }
        }
        part.setModel(model);
        return part;
    }
});
/**
 * @author 郑佳超
 * @since 2017-4-6
 */
ADF.ControlFactory = function ControlFactory(controlList) {
    this.controlList = controlList;
    ADF.ControlFactory.superclass.constructor.call(this);
    this._init();
};
COM.util.defineClass(ADF.ControlFactory, AGEF.DefaultControlFactory, {

    _init: function () {
        this.controlList.forEach(function (control) {
            this.registryControlClass(control.getModel(), control.getDomControl());
        }, this);
    }
});
/**
 * @author zhengjiachao
 * @since 2017-3-27
 */
ADF.Designer = function Designer(shell, contents, bundleList) {
    this.contents = contents;
    this.shell = shell;
    this.editorContainer = shell;
    this._createContainers(shell);
    this.bundleList = bundleList || this._getBundleList();
    this.resolvedBundles = this._resolveBundles();
    this.hotkeyHolder = new AGEF.HotkeyHolder();
    var inputs = {
        'editorContainer': this._getEditorContainer(),
        'graphicalContainer': this._getGraphicalContainer(),
        'paletteContainer': this._getPaletteContainer(),
        'toolbarContainer': this._getToolbarContainer(),
        'propertyContainer': this._getPropertyContainer(),
        'outlineContainer': this._getOutlineContainer(),
        'editPartFactory': this._getEditPartFactory(),
        'widgetFactory': this._getWidgetFactory(),
        'contents': this._getContents(),
        'paletteContents': this._getPaletteContents(),
        'propertyContents': this._getPropertyContents(),
        'toolbarContents': this._getToolbarContents()
    };
    ADF.Designer.superclass.constructor.call(this, inputs);
}

COM.util.defineClass(ADF.Designer, AGEF.DefaultEditor, {

    //override
    createPaletteViewers: function (inputs) {
        var viewers = ADF.Designer.superclass.createPaletteViewers.call(this, inputs);
        viewers[0].registerControl(AGEF.ToolEntry.LABEL, ADF.ToolEntry);
        return viewers;
    },

    //override
    //@king
    createGraphicalViewers: function (inputs) {
        var graphicalViewers = ADF.Designer.superclass.createGraphicalViewers.call(this, inputs);
        var designer = this;
        if (graphicalViewers && graphicalViewers.length > 0) {
            for (var i = 0; i < graphicalViewers.length; i++) {
                var graphicalViewer = graphicalViewers[i];
                graphicalViewer.setKeyHandler({
                    keyDown: function keyDown(e) {
                        designer.hotkeyHolder.execute(e, graphicalViewer);
                        e.preventDefault();
                    },
                    keyPressed : function keyPressed(e){
                        designer.hotkeyHolder.execute(e, graphicalViewer);
                        e.preventDefault();
                    },
                    keyReleased : function keyReleased(e){
                        designer.hotkeyHolder.execute(e, graphicalViewer);
                        e.preventDefault();
                    }
                });
            }
        }
        return graphicalViewers;
    },

    _resolveBundles: function () {
        var r = {
            Action: [],
            Control: [],
            Property: [],
            Tool: []
        };
        for (var i = 0; i < this.bundleList.length; i++) {
            var bundle = this.bundleList[i];
            r[bundle.getType()].push(bundle);
        }
        return r;
    },
    //插件列表，列表返回
    _getBundleList: Function.needOverride,

    _getEditorContainer: function () {
        return this.shell;
    },

    _getGraphicalContainer: function () {
        return document.getElementById("adf_content_container");
    },

    _getPaletteContainer: function () {
        return document.getElementById("adf_palette_container");
    },

    _getOutlineContainer: function () {
        return document.getElementById("adf_outline_container");
    },

    _getPropertyContainer: function () {
        return document.getElementById("adf_property_container");
    },

    _getToolbarContainer: function () {
        return document.getElementById('adf_action_container');
    },

    _getEditPartFactory: function () {
        return new ADF.PartFactory(this.resolvedBundles['Control']);
    },


    _getWidgetFactory: function () {
        return new ADF.ControlFactory(this.resolvedBundles['Control']);
    },


    _getContents: function () {
        return this.contents;
    },

    _getPaletteContents: function () {
        var tools = this.resolvedBundles['Tool'];
        // 1. 初始化分组  2.初始化工具  3.把工具放入分组   4.把分组返回
        var contents = [];
        var groups = {};
        tools.forEach(function (tool) {
            var ins = tool.getGroupInstance();
            if (ins) {
                groups[ins['id']] = ins['instance'];
                contents.push(ins['instance']);
            }
        }, this);
        tools.forEach(function (tool) {
            var ins = tool.getToolModelInstance();
            if (ins) {
                groups[ins['id']].addToolModel(ins['instance']);
            }
        }, this);
        return contents;
    },

    _getPropertyContents: function () {
        var properties = this.resolvedBundles['Property'];
        var contents = [];
        var groups = {};
        properties.forEach(function (property) {
            var ins = property.getGroupInstance();
            if (ins) {
                contents.push(ins);
            }
        }, this);
        return contents;
    },

    _getToolbarContents: function () {
        var actions = this.resolvedBundles['Action'];
        var contents = [];
        actions.forEach(function (action) {
            var ins = action.getModelInstance();
            if (ins) {
                contents.push(ins);
                this.hotkeyHolder.registerAction(ins);
            }
        }, this);
        return contents;
    },

    _createContainers: function (shell) {
        shell.className = shell.className + " container_fluid";
        shell.innerHTML =
            '<div class="ui-layout-north" id="adf_action_container"></div>' +

            '<div class="ui-layout-west" id="adf_palette_container"></div>' +
            '<div class="ui-layout-east" style="border:none;padding: 0">'+
            '<div class="ui-layout-center" id="adf_property_container">'+
            '<div class="adf_property_container">元素属性<i class="iconfont icon-arrow"></i></div>'+
            '</div>'+
            '<div class="ui-layout-north" id="adf_outline_container">'+
            '<div class="adf_outline_container">结构<i class="iconfont icon-arrow"></div>'+
            '</div></div>'+
            '<div class="ui-layout-center" id="adf_content_container"></div>';

        var myLayout=$(shell).layout({
            spacing_open:1,
            spacing_closed:1,
            resizerTip:"可调整大小",
            sliderTip:"显示/隐藏侧边栏",
            togglerTip_open:"关闭",
            togglerTip_closed:"打开",
            togglerLength_open:50,
            togglerLength_closed:50,
            north:{
                size:40,
                minSize:20,
                maxSize:100
            },
            west:{
                size:317,
                minSize:115,
                maxSize:0.5
            },
            east:{
                size:0.2,
                minSize:200,
                maxSize:0.5
            },
            center:{
                minWidth:100
            }
        });
        $(".ui-layout-east").layout({
            spacing_open:1,
            spacing_closed:1,
            resizerTip:"可调整大小",
            sliderTip:"显示/隐藏侧边栏",
            togglerTip_open:"关闭",
            togglerTip_closed:"打开",
            togglerLength_open:50,
            togglerLength_closed:50,
            north:{
                size:0.5,
                minSize:100,
                maxSize:0.9
            }
        });

    },

    configurePropertyControl: function (propertyViewer) {
        ADF.Designer.superclass.configurePropertyControl.call(this, propertyViewer);
        propertyViewer.registerControl(AGEF.TextPropertyEditor.LABEL, ADF.TextPropertyEditor);
        propertyViewer.registerControl(ADF.AttrColorPropertyEditor.LABEL, ADF.AttrColorPropertyEditor);
        var properties = this.resolvedBundles['Property'];
        properties.forEach(function (property) {
            var control = property.getEditorControl();
            if (control) {
                propertyViewer.registerControl(control.getID(), control);
            }
            var modalRenderer = property.getModalRenderer();
            if (modalRenderer) {
                var $renderContainer = $('<div></div>');
                $(shell).append($renderContainer);
                modalRenderer.init($renderContainer[0]);
                ADF.registerModalRenderer(modalRenderer.getID(), modalRenderer);
            }
        }, this);
    }

});/**
 * @author zhengjiachao
 * @since 2017-3-27
 */
ADF.BundleDescriptor = function(){
    ADF.BundleDescriptor.superclass.constructor.call(this);
    this.id = (function getRandomId(){
        var getRandomStr = function(){
            var str = Math.random().toString(26);
            return str.substring(2, str.length);
        };
        return "A" + getRandomStr() + getRandomStr();
    });
};

COM.util.defineClass(ADF.BundleDescriptor, Object,{

    getType : Function.needOverride,

    getId : function(){
        return this.id;
    }
    
});/**
 * @author zhengjiachao
 * @since 2017-3-27
 */
ADF.ActionDescriptor = function(){
    ADF.ActionDescriptor.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.ActionDescriptor, ADF.BundleDescriptor,{

    getType : function(){
        return "Action";
    },

    /**
     * 返回一个动作的实例对象
     * 
     */
    getModelInstance : function(){
        return null;
    }
});/**
 * @author zhengjiachao
 * @since 2017-3-27
 */
ADF.ControlDescriptor = function(){
    ADF.ControlDescriptor.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.ControlDescriptor, ADF.BundleDescriptor,{

    getType : function(){
        return "Control";
    },

    getEditpart : Function.needOverride,

    getModel : Function.needOverride,

    getDomControl : function(){}

});/**
 * @author zhengjiachao
 * @since 2017-3-27
 */
ADF.CompositeDescriptor = function(){
    ADF.CompositeDescriptor.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.CompositeDescriptor, ADF.ControlDescriptor,{

    

});/**
 * @author zhengjiachao
 * @since 2017-3-27
 */
ADF.PropertyDescriptor = function(){
    ADF.PropertyDescriptor.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.PropertyDescriptor, ADF.BundleDescriptor,{

    getType : function(){
        return "Property";
    },

    getGroupInstance : function(){
        return null;
    },

    getEditorControl : function(){
        return null;
    },

    getModalRenderer : function(){
        return null;
    }

});/**
 * @author zhengjiachao
 * @since 2017-3-27
 */
ADF.ToolDescriptor = function(){
    ADF.ToolDescriptor.superclass.constructor.call(this);
};

COM.util.defineClass(ADF.ToolDescriptor, ADF.BundleDescriptor,{

    getType : function(){
        return "Tool";
    },

    /**
     * 返回分组定义的一个实例对象，机制会根据分组的实例对象，展示工具界面，并把相应的工具放到分组里
     * 返回值的格式是 {id, instance}
     * id是分组的id，其他工具根据id放入分组， instance是分组对象的一个实例
     */
    getGroupInstance : function(){
        return null;
    },

    /**
     * 返回一个工具的实例对象，机制会把工具放到对应的分组中
     * 返回值的格式是 {id, instance}
     * id是分组的id，工具根据id放入预先定义好的分组， instance是工具对象的一个实例
     */
    getToolModelInstance : function(){
        return null;
    }
});ADF.ToolEntry = function() {
    ADF.ToolEntry.superclass.constructor.call(this);
};
COM.util.defineClass(ADF.ToolEntry, AGEF.ToolEntry, {
    createControl: function(model) {
        var control = null;
        if (model.getModel()) {
            control = COM.util.HTMLUtil.createELement('<button type="button" class="btn btn-default palette_config" title="' + model.getModel().getConfig().text + '"><i class="iconfont '+model.getModel().getConfig().icon+'"></i><span class="iconfont_text">' + model.getModel().getConfig().text + '</span></button>');
        } else {
            control = COM.util.HTMLUtil.createELement('<button type="button" class="btn btn-default col-sm-2"><span class="iconfont icon-xuanze"></span></button>');
        };
        this.control = control[0];
    }
});/**
 * Created by zhangwenlei on 2017/4/13.
 */
ADF.TextPropertyEditor=function (propDescriptor) {
    ADF.TextPropertyEditor.superclass.constructor.call(this,propDescriptor);
};

COM.util.defineClass(ADF.TextPropertyEditor,AGEF.TextPropertyEditor,{
    createControl:function (propDescriptor) {
        var controlString =  '<div class="form-horizontal" style="margin-bottom:5px;"><div class="form-group" style="position: relative;">' +
            '<div class="col-sm-3" style="margin-left: 2px"><label style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap" for="'+propDescriptor.getName()+ '" class="control-label" title="'+propDescriptor.getHint()+'">'+propDescriptor.getTitle()+'</label></div>' +
            '<div class="col-sm-9" style="margin-left: -25px">' +
            '<input type="text" class="form-control" id="'+propDescriptor.getName()+ '" value="'+propDescriptor.getValue()+ '">' +
            '</div></div></div>';
        var control = COM.util.HTMLUtil.createELement(controlString);
        this.control = control[0];
    }
});ADF.AttrColorPropertyEditor = function(propDescriptor) {
        ADF.AttrColorPropertyEditor.superclass.constructor.call(this, propDescriptor);
    };
    ADF.AttrColorPropertyEditor.LABEL = "attrColorEditor";
    COM.util.defineClass(ADF.AttrColorPropertyEditor, AGEF.PropertyEditor, {
        createControl: function(propDescriptor) {
            var controlString =  '<div class="form-horizontal" style="margin-bottom:5px;"><div class="form-group" style="position: relative;">' +
            '<div class="col-sm-3" style="margin-left: 2px"><label style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap" for="'+propDescriptor.getName()+ '" class="control-label" title="'+propDescriptor.getHint()+'">'+propDescriptor.getTitle()+'</label></div>' +
            '<div class="col-sm-9" style="margin-left: -25px">' +
            '<input type="text" style="display:none;" class="form-control fontBgColor" id="'+propDescriptor.getName()+ '" value="'+propDescriptor.getValue()+ '">' +
            '</div></div></div>';
            var control = COM.util.HTMLUtil.createELement(controlString);
            this.control = control[0];
            var fontBgColor = COM.util.HTMLUtil.getChildren(this.control, ".fontBgColor");
            $(fontBgColor).spectrum({
                color:"#000000",
                flat:false,
                showInput:true,
                showInitial:true,
                allowEmpty:true,
                showAlpha:true,
                showPaletteOnly: true,
                hideAfterPaletteSelect:true,
                togglePaletteOnly: true,
                cancelText: "取消",
                chooseText:"确定",
                togglePaletteMoreText: "自定义颜色",
                togglePaletteLessText: "隐藏自定义",
                containerClassName: "fontBgCon",
                replacerClassName: "fontBgRep",
                preferredFormat: "rgb",
                palette: [
                   ["#000","#444","#666","#999","#ccc","#eee","#f3f3f3","#fff"],
                   ["#f00","#f90","#ff0","#0f0","#0ff","#00f","#90f","#f0f"],
                   ["#f4cccc","#fce5cd","#fff2cc","#d9ead3","#d0e0e3","#cfe2f3","#d9d2e9","#ead1dc"],
                   ["#ea9999","#f9cb9c","#ffe599","#b6d7a8","#a2c4c9","#9fc5e8","#b4a7d6","#d5a6bd"],
                   ["#e06666","#f6b26b","#ffd966","#93c47d","#76a5af","#6fa8dc","#8e7cc3","#c27ba0"],
                   ["#c00","#e69138","#f1c232","#6aa84f","#45818e","#3d85c6","#674ea7","#a64d79"],
                   ["#900","#b45f06","#bf9000","#38761d","#134f5c","#0b5394","#351c75","#741b47"],
                   ["#600","#783f04","#7f6000","#274e13","#0c343d","#073763","#20124d","#4c1130"],
                   ["transparent"]
                ],
                clearText:"清除颜色",
                noColorSelectedText:"透明",
                showButtons:true
            });
            $(fontBgColor).spectrum("set",$(fontBgColor).val());
            var fontBgRep = COM.util.HTMLUtil.getChildren(this.control, ".fontBgRep");
            $(fontBgRep).find(".sp-dd").remove();
        },
        getControl: function() {
            return this.control;
        },
        setValue: function(value) {
            if(value != this.getValue()) {
                COM.util.HTMLUtil.getChildren(this.control, ".fontBgColor").attr("value",value);
            }
        },
        getValue: function() {
            var value = COM.util.HTMLUtil.getChildren(this.control, ".fontBgColor").val();
            return value;
        },
        bindChangeHandler: function(handler) {
            COM.util.HTMLUtil.getChildren(this.control, ".fontBgColor").bind('change.spectrum', function(e,color) {
                var request = new AGEF.ChangeValueRequest();
                request.setPropertyName(this.propDescriptor.getName());
                request.setValue(color.toRgbString());
                handler(request);
            }.bind(this));
        }
    });